package com.igeek.health.mapper;

import com.igeek.health.entity.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.Set;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author fengqq
 * @since 2024-08-26
 */
public interface RoleMapper extends BaseMapper<Role> {

    //根据管理员id 查询 相关的角色信息
    //@Select("select r.* from role r join user_role ur on r.id=ur.role_id where ur.user_id=#{userId}")
    //public Set<Role> selectRolesByUserId(@Param("userId") Integer userId);

    //根据管理员id查询 角色列表
    @Select("select r.* from role r join user_role ur on r.id=ur.role_id where ur.user_id=#{userId}")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(
                    property = "permissions",javaType =Set.class ,
                    column = "id",
                    many = @Many(select = "com.igeek.health.mapper.PermissionMapper.selectPermissionsByRoleId"))
    })
    public Set<Role> selectRolesByUserId(Integer userId);

}
